package evolutionaryballoons;

import static evolutionaryballoons.Configuration.sHeight;
import static evolutionaryballoons.Configuration.sNumberOfCurrents;

import java.util.Random;

public class Currents {
	private float[] segments;
	
	public Currents() {
		Random random = new Random();
		segments = new float[sNumberOfCurrents];
		
		for (int i = 0; i < sNumberOfCurrents; i++) {
			segments[i] = random.nextFloat() * 2.0f - 1.0f;
		}
	}
	
	public float get(int index) {
		if (index < 0) {
			index = 0;
		}
		
		if (index >= sNumberOfCurrents) {
			index = sNumberOfCurrents - 1;
		}
		
		return segments[index];
	}
	
	protected float getWindAt(double y) {
		int iy = (int) ((y * sNumberOfCurrents) / sHeight);
		
		return get(iy);
	}
}
